package com.tancire.question.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.question.domain.TrainProblemType;
import com.tancire.question.service.ITrainProblemTypeService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 问题类型Controller
 *
 * @author tancire
 * @date 2024-10-09
 */
@RestController
@RequestMapping("/question/trainProblemType")
public class TrainProblemTypeController extends BaseController {
    @Resource
    private ITrainProblemTypeService trainProblemTypeService;

    /**
     * 查询问题类型列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainProblemType trainProblemType) {
        startPage();
        List<TrainProblemType> list = trainProblemTypeService.selectTrainProblemTypeList(trainProblemType);
        return getDataTable(list);
    }

    /**
     * 查询问题类型列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll() {
        List<TrainProblemType> list = trainProblemTypeService.selectTrainProblemTypeList(new TrainProblemType());
        return AjaxResult.success(list);
    }

    /**
     * 导出问题类型列表
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:export')")
    @Log(title = "问题类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainProblemType trainProblemType) {
        List<TrainProblemType> list = trainProblemTypeService.selectTrainProblemTypeList(trainProblemType);
        ExcelUtil<TrainProblemType> util = new ExcelUtil<TrainProblemType>(TrainProblemType.class);
        util.exportExcel(response, list, "问题类型数据");
    }

    /**
     * 获取问题类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(trainProblemTypeService.selectTrainProblemTypeById(id));
    }

    /**
     * 新增问题类型
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:add')")
    @Log(title = "问题类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainProblemType trainProblemType) {
        return toAjax(trainProblemTypeService.insertTrainProblemType(trainProblemType));
    }

    /**
     * 修改问题类型
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:edit')")
    @Log(title = "问题类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainProblemType trainProblemType) {
        return toAjax(trainProblemTypeService.updateTrainProblemType(trainProblemType));
    }

    /**
     * 删除问题类型
     */
    @PreAuthorize("@ss.hasPermi('question:trainProblemType:remove')")
    @Log(title = "问题类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainProblemTypeService.deleteTrainProblemTypeByIds(ids));
    }
}
